package com.goodving.guli.bt.profile.scale;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.content.Context;
import android.util.Log;

import com.goodving.guli.bt.C1725b;
import com.goodving.guli.bt.model.C3911i;
import com.goodving.guli.bt.model.C3919q;
import com.goodving.guli.bt.utils.ProfileUtils;
import com.goodving.guli.utility.Constants;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by john on 2015/11/25.
 */
public final class WeightProfile extends GattPeripheral { // C3926f
    public static final String f19776m = "2.0.5.20141206";
    public static final String TAG = "WeightProfile";
    public static final int f19778o = 0;
    public static final int f19779p = 1;
    public static final int f19780q = 2;
    public static final int f19781r = 3;
    public static final int f19782s = 4;
    private BluetoothGattCharacteristic f19783A;
    private BluetoothGattCharacteristic f19784B;
    private C3847c f19785C;
    private C3849b f19786D;
    private ExecutorService f19787E;
    private boolean f19788F;
    private byte[] f19789G;
    private C3911i f19790H;
    private final int f19791I;
    private final int f19792J;
    private BluetoothGattService f19793t;
    private BluetoothGattCharacteristic f19794u;
    private BluetoothGattCharacteristic f19795v;
    private BluetoothGattCharacteristic f19796w;
    private BluetoothGattCharacteristic f19797x;
    private BluetoothGattCharacteristic f19798y;
    private BluetoothGattCharacteristic f19799z;

    private BluetoothGattCharacteristic charc_write;
    private BluetoothGattCharacteristic charc_data;
    private BluetoothGattCharacteristic charc_record;

    private static int devType = Constants.DEV_FRK_SCALE;

    static {
        GuliLog.INFO(WeightProfile.class.getSimpleName() + ".VERSION: " + f19776m);
    }

    public interface C3849b {
        void m25173a();
    }

    public interface C3847c {
        void m25171a(ScaleWeightInfo c3925e);
    }

    public WeightProfile(Context context, BluetoothDevice bluetoothDevice, C1724A c1724a) {
        super(context, bluetoothDevice, c1724a);
        this.f19793t = null;
        this.f19794u = null;
        this.f19795v = null;
        this.f19796w = null;
        this.f19797x = null;
        this.f19798y = null;
        this.f19799z = null;
        this.f19783A = null;
        this.f19784B = null;
        this.f19785C = null;
        this.f19786D = null;
        this.f19787E = Executors.newSingleThreadExecutor();
        this.f19788F = false;
        this.f19789G = null;
        this.f19790H = null;
        this.f19791I = f19781r;
        this.f19792J = 259;
        GuliLog.m12371e();
    }

    private int m25504A() {
        byte[] g = read(this.f19784B);
        if (g == null || g.length < f19780q) {
            GuliLog.m12370d(TAG, "getSandglassMode failed!!!");
            return -1;
        }
        GuliLog.m12370d(TAG, "Sandglass mode : " + GattUtils.m25335b(g));
        return (g[f19778o] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[f19779p] & HeartRateInfo.HR_EMPTY_VALUE) << 8);
    }

    private boolean m25505B() {
        GuliLog.m12370d(TAG, "setSandglassToUserMode");
        return write(this.f19784B, new byte[]{(byte) 3, (byte) 1, (byte) 0, (byte) 0, (byte) 0});
    }

    private C3911i m25506C() {
        C3911i c3911i = new C3911i();
        byte[] g = read(this.f19795v);
        if (g != null && g.length >= 6) {
            byte[] obj = new byte[6];
            System.arraycopy(g, f19778o, obj, f19778o, 6);
            c3911i.f19720c = new String(obj);
        }
        byte[] g2 = read(this.f19797x);
        if (g2 != null && g2.length == 8) {
            c3911i.f19718a = String.format("%02X%02X%02X%02X%02X%02X%02X%02X", new Object[]{Byte.valueOf(g2[f19778o]), Byte.valueOf(g2[f19779p]), Byte.valueOf(g2[f19780q]), Byte.valueOf(g2[f19781r]), Byte.valueOf(g2[f19782s]), Byte.valueOf(g2[5]), Byte.valueOf(g2[6]), Byte.valueOf(g2[7])});
        }
        if (this.f19796w != null) {
            g2 = read(this.f19796w);
            if (g2 != null && g2.length > 0) {
                c3911i.f19719b = new String(g2);
            }
        }
        if (this.f19798y != null) {
            g2 = read(this.f19798y);
            if (g2 != null && g2.length == 7) {
                GuliLog.tracePrintInfo(TAG, "pnp id:" + GattUtils.m25335b(g2));
                C3919q c3919q = new C3919q();
                c3919q.f19738d = g2[f19778o] & HeartRateInfo.HR_EMPTY_VALUE;
                c3919q.f19735a = ((g2[f19780q] & HeartRateInfo.HR_EMPTY_VALUE) << 8) | (g2[f19779p] & HeartRateInfo.HR_EMPTY_VALUE);
                c3919q.f19736b = ((g2[f19782s] & HeartRateInfo.HR_EMPTY_VALUE) << 8) | (g2[f19781r] & HeartRateInfo.HR_EMPTY_VALUE);
                c3919q.f19737c = (g2[5] & HeartRateInfo.HR_EMPTY_VALUE) | ((g2[6] & HeartRateInfo.HR_EMPTY_VALUE) << 8);
                c3911i.f19721d = c3919q;
            }
        }
        GuliLog.m12370d(TAG, "device info:" + c3911i);
        return c3911i;
    }

    private boolean m25510a(Calendar calendar) {
        GuliLog.m12371e();
        short s = (short) calendar.get(Calendar.YEAR);
        byte b = (byte) (calendar.get(Calendar.MONTH) + f19779p);
        byte b2 = (byte) calendar.get(Calendar.DATE);
        byte b3 = (byte) calendar.get(Calendar.HOUR_OF_DAY);
        byte b4 = (byte) calendar.get(Calendar.MINUTE);
        byte b5 = (byte) calendar.get(Calendar.SECOND);
        GattUtils.m25329a(new byte[f19780q], (int) f19778o, s);
        byte b6 = (byte) calendar.get(Calendar.DAY_OF_WEEK);

        GuliLog.m12370d(TAG, "year:" + s + ",month:" + b + ",day:" + b2 + ",hour:" + b3 + ",min:" + b4 + ",sec:" + b5);
        return write(this.f19799z, new byte[]{0, 0, b, b2, b3, b4, b5, b6, (byte) 0, (byte) 0});
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
//    private int m25512b(java.lang.String r21, com.goodving.hm.health.bt.p066d.C1725b r22) {
//        /*
//        r20 = this;
//        r2 = 0;
//        r11 = 10000; // 0x2710 float:1.4013E-41 double:4.9407E-320;
//        r4 = 0;
//        r3 = new java.util.UUID;
//        r6 = 13586; // 0x3512 float:1.9038E-41 double:6.7124E-320;
//        r8 = 2384656044284446464; // 0x21180009af100700 float:-1.309921E-10 double:2.932756965301042E-149;
//        r3.<init>(r6, r8);
//        r5 = 5424; // 0x1530 float:7.6E-42 double:2.68E-320;
//        r5 = com.goodving.hm.health.bt.p094c.GattUtils.m25323a(r3, r5);
//        r0 = r20;
//        r5 = r0.getService(r5);
//        if (r5 != 0) goto L_0x0027;
//    L_0x001e:
//        r2 = "WeightProfile";
//        r3 = "service dfu is null!!!";
//        cn.com.smartdevices.bracelet.GuliLog.tracePrintInfo(r2, r3);
//        r2 = 1;
//    L_0x0026:
//        return r2;
//    L_0x0027:
//        r6 = 5425; // 0x1531 float:7.602E-42 double:2.6803E-320;
//        r6 = com.goodving.hm.health.bt.p094c.GattUtils.m25323a(r3, r6);
//        r12 = r5.getCharacteristic(r6);
//        r6 = 5426; // 0x1532 float:7.603E-42 double:2.681E-320;
//        r3 = com.goodving.hm.health.bt.p094c.GattUtils.m25323a(r3, r6);
//        r13 = r5.getCharacteristic(r3);
//        if (r12 == 0) goto L_0x003f;
//    L_0x003d:
//        if (r13 != 0) goto L_0x0048;
//    L_0x003f:
//        r2 = "WeightProfile";
//        r3 = "BluetoothGattCharacteristic cpt or pkt is null!!!";
//        cn.com.smartdevices.bracelet.GuliLog.tracePrintInfo(r2, r3);
//        r2 = 1;
//        goto L_0x0026;
//    L_0x0048:
//        r3 = new com.goodving.hm.health.bt.profile.Weight.i;
//        r0 = r20;
//        r3.<init>(r0, r12);
//        r0 = r20;
//        r3 = r0.registerNotification(r12, r3);
//        if (r3 != 0) goto L_0x0060;
//    L_0x0057:
//        r2 = "WeightProfile";
//        r3 = "Fail subscribe to DFU control point!";
//        cn.com.smartdevices.bracelet.GuliLog.tracePrintInfo(r2, r3);
//        r2 = 1;
//        goto L_0x0026;
//    L_0x0060:
//        r8 = 65535; // 0xffff float:9.1834E-41 double:3.23786E-319;
//        r5 = new java.io.File;	 Catch:{ Exception -> 0x0432, all -> 0x0453 }
//        r0 = r21;
//        r5.<init>(r0);	 Catch:{ Exception -> 0x0432, all -> 0x0453 }
//        r3 = new java.io.BufferedInputStream;	 Catch:{ Exception -> 0x0432, all -> 0x0453 }
//        r6 = new java.io.FileInputStream;	 Catch:{ Exception -> 0x0432, all -> 0x0453 }
//        r6.<init>(r5);	 Catch:{ Exception -> 0x0432, all -> 0x0453 }
//        r3.<init>(r6);	 Catch:{ Exception -> 0x0432, all -> 0x0453 }
//        r4 = r5.length();	 Catch:{ Exception -> 0x0468 }
//        r4 = (int) r4;	 Catch:{ Exception -> 0x0468 }
//        r4 = r4 << 8;
//        r4 = r4 | 1;
//        r5 = 4;
//        r5 = new byte[r5];	 Catch:{ Exception -> 0x0468 }
//        r6 = 0;
//        com.goodving.hm.health.bt.p094c.GattUtils.m25328a(r5, r6, r4);	 Catch:{ Exception -> 0x0468 }
//        r14 = r4 >> 8;
//        r4 = 0;
//        r0 = r20;
//        r0.f19789G = r4;	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r0.write(r12, r5);	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        if (r4 != 0) goto L_0x009b;
//    L_0x0096:
//        r0 = r20;
//        r0.m25521a(r12, r11);	 Catch:{ Exception -> 0x0468 }
//    L_0x009b:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        if (r4 == 0) goto L_0x00c8;
//    L_0x00a1:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.length;	 Catch:{ Exception -> 0x0468 }
//        r5 = 3;
//        if (r4 < r5) goto L_0x00c8;
//    L_0x00a9:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 0;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 16;
//        if (r4 != r5) goto L_0x00c8;
//    L_0x00b4:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        if (r4 != r5) goto L_0x00c8;
//    L_0x00be:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 2;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        if (r4 == r5) goto L_0x010f;
//    L_0x00c8:
//        r2 = "WeightProfile";
//        r4 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x0468 }
//        r4.<init>();	 Catch:{ Exception -> 0x0468 }
//        r5 = "Invalid response: ";
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r5 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = com.goodving.hm.health.bt.p094c.GattUtils.m25335b(r5);	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r5 = ",lenght:";
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r5 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = r5.length;	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.toString();	 Catch:{ Exception -> 0x0468 }
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r2, r4);	 Catch:{ Exception -> 0x0468 }
//        r2 = 1;
//        if (r3 == 0) goto L_0x00fd;
//    L_0x00fa:
//        r3.close();	 Catch:{ IOException -> 0x0106 }
//    L_0x00fd:
//        if (r12 == 0) goto L_0x0026;
//    L_0x00ff:
//        r0 = r20;
//        r0.unregisterNotification(r12);
//        goto L_0x0026;
//    L_0x0106:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x00fd;
//    L_0x010f:
//        r4 = 0;
//        r0 = r20;
//        r0.f19789G = r4;	 Catch:{ Exception -> 0x0468 }
//        r4 = 1;
//        r4 = new byte[r4];	 Catch:{ Exception -> 0x0468 }
//        r5 = 0;
//        r6 = 3;
//        r4[r5] = r6;	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r4 = r0.write(r12, r4);	 Catch:{ Exception -> 0x0468 }
//        if (r4 != 0) goto L_0x0142;
//    L_0x0123:
//        r2 = "WeightProfile";
//        r4 = "write DFU_OPCODE_TRANSFER failed!!!";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r2, r4);	 Catch:{ Exception -> 0x0468 }
//        r2 = 1;
//        if (r3 == 0) goto L_0x0130;
//    L_0x012d:
//        r3.close();	 Catch:{ IOException -> 0x0139 }
//    L_0x0130:
//        if (r12 == 0) goto L_0x0026;
//    L_0x0132:
//        r0 = r20;
//        r0.unregisterNotification(r12);
//        goto L_0x0026;
//    L_0x0139:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x0130;
//    L_0x0142:
//        r4 = 20;
//        r9 = new byte[r4];	 Catch:{ Exception -> 0x0468 }
//        if (r22 == 0) goto L_0x014d;
//    L_0x0148:
//        r0 = r22;
//        r0.setMax(r14);	 Catch:{ Exception -> 0x0468 }
//    L_0x014d:
//        r7 = 0;
//        r5 = 0;
//        r6 = 0;
//        r4 = 0;
//        r10 = "WeightProfile";
//        r15 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x0468 }
//        r15.<init>();	 Catch:{ Exception -> 0x0468 }
//        r16 = "Device firmware: ";
//        r15 = r15.append(r16);	 Catch:{ Exception -> 0x0468 }
//        r0 = r21;
//        r15 = r15.append(r0);	 Catch:{ Exception -> 0x0468 }
//        r16 = ", ";
//        r15 = r15.append(r16);	 Catch:{ Exception -> 0x0468 }
//        r15 = r15.append(r14);	 Catch:{ Exception -> 0x0468 }
//        r16 = " bytes";
//        r15 = r15.append(r16);	 Catch:{ Exception -> 0x0468 }
//        r15 = r15.toString();	 Catch:{ Exception -> 0x0468 }
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r10, r15);	 Catch:{ Exception -> 0x0468 }
//        r16 = java.lang.System.currentTimeMillis();	 Catch:{ Exception -> 0x0468 }
//        r10 = r8;
//        r8 = r5;
//        r5 = r9;
//        r19 = r4;
//        r4 = r7;
//        r7 = r19;
//    L_0x0187:
//        r9 = 1999; // 0x7cf float:2.801E-42 double:9.876E-321;
//        r4 = r4 + r6;
//        if (r9 >= r4) goto L_0x01c7;
//    L_0x018c:
//        r4 = 0;
//        r6 = "WeightProfile";
//        r9 = "Insert write request to clear GKI buffer!";
//        cn.com.smartdevices.bracelet.GuliLog.tracePrintInfo(r6, r9);	 Catch:{ Exception -> 0x0468 }
//        r6 = 1;
//        r6 = new byte[r6];	 Catch:{ Exception -> 0x0468 }
//        r9 = 0;
//        r15 = 0;
//        r6[r9] = r15;	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r6 = r0.write(r12, r6);	 Catch:{ Exception -> 0x0468 }
//        if (r6 != 0) goto L_0x01c7;
//    L_0x01a3:
//        r2 = "WeightProfile";
//        r4 = "write DFU_OPCODE_DUMMY failed!!!";
//        cn.com.smartdevices.bracelet.GuliLog.tracePrintInfo(r2, r4);	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r0.m25514b(r12, r10);	 Catch:{ Exception -> 0x0468 }
//        r2 = 1;
//        if (r3 == 0) goto L_0x01b5;
//    L_0x01b2:
//        r3.close();	 Catch:{ IOException -> 0x01be }
//    L_0x01b5:
//        if (r12 == 0) goto L_0x0026;
//    L_0x01b7:
//        r0 = r20;
//        r0.unregisterNotification(r12);
//        goto L_0x0026;
//    L_0x01be:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x01b5;
//    L_0x01c7:
//        r6 = r4;
//        r4 = 0;
//        r9 = r5.length;	 Catch:{ Exception -> 0x0468 }
//        r9 = r3.read(r5, r4, r9);	 Catch:{ Exception -> 0x0468 }
//        r4 = 1;
//        if (r9 >= r4) goto L_0x023d;
//    L_0x01d1:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        if (r4 != 0) goto L_0x01dc;
//    L_0x01d7:
//        r0 = r20;
//        r0.m25521a(r12, r11);	 Catch:{ Exception -> 0x0468 }
//    L_0x01dc:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        if (r4 == 0) goto L_0x0209;
//    L_0x01e2:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.length;	 Catch:{ Exception -> 0x0468 }
//        r5 = 3;
//        if (r4 < r5) goto L_0x0209;
//    L_0x01ea:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 0;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 16;
//        if (r4 != r5) goto L_0x0209;
//    L_0x01f5:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 3;
//        if (r4 != r5) goto L_0x0209;
//    L_0x01ff:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 2;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        if (r4 == r5) goto L_0x02b7;
//    L_0x0209:
//        r2 = "WeightProfile";
//        r4 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x0468 }
//        r4.<init>();	 Catch:{ Exception -> 0x0468 }
//        r5 = "Invalid response: ";
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r5 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = com.goodving.hm.health.bt.p094c.GattUtils.m25335b(r5);	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.toString();	 Catch:{ Exception -> 0x0468 }
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r2, r4);	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r0.m25514b(r12, r10);	 Catch:{ Exception -> 0x0468 }
//        r2 = 1;
//        if (r3 == 0) goto L_0x0234;
//    L_0x0231:
//        r3.close();	 Catch:{ IOException -> 0x02ad }
//    L_0x0234:
//        if (r12 == 0) goto L_0x0026;
//    L_0x0236:
//        r0 = r20;
//        r0.unregisterNotification(r12);
//        goto L_0x0026;
//    L_0x023d:
//        r4 = 0;
//        r10 = com.goodving.hm.health.bt.p094c.GattUtils.m25318a(r10, r5, r4, r9);	 Catch:{ Exception -> 0x0468 }
//        r4 = r5.length;	 Catch:{ Exception -> 0x0468 }
//        if (r9 >= r4) goto L_0x0475;
//    L_0x0245:
//        r4 = new byte[r9];	 Catch:{ Exception -> 0x0468 }
//        r15 = 0;
//        r18 = 0;
//        r0 = r18;
//        java.lang.System.arraycopy(r5, r15, r4, r0, r9);	 Catch:{ Exception -> 0x0468 }
//    L_0x024f:
//        r0 = r20;
//        r5 = r0.write(r13, r4);	 Catch:{ Exception -> 0x0468 }
//        if (r5 != 0) goto L_0x027b;
//    L_0x0257:
//        r2 = "WeightProfile";
//        r4 = "write firmware data failed!!!";
//        cn.com.smartdevices.bracelet.GuliLog.tracePrintInfo(r2, r4);	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r0.m25514b(r12, r10);	 Catch:{ Exception -> 0x0468 }
//        r2 = 1;
//        if (r3 == 0) goto L_0x0269;
//    L_0x0266:
//        r3.close();	 Catch:{ IOException -> 0x0272 }
//    L_0x0269:
//        if (r12 == 0) goto L_0x0026;
//    L_0x026b:
//        r0 = r20;
//        r0.unregisterNotification(r12);
//        goto L_0x0026;
//    L_0x0272:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x0269;
//    L_0x027b:
//        r15 = r8 * r14;
//        r5 = r7 + r9;
//        r7 = r5 * 100;
//        if (r15 >= r7) goto L_0x0470;
//    L_0x0283:
//        r7 = r5 * 100;
//        r7 = r7 / r14;
//        r8 = "WeightProfile";
//        r15 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x0468 }
//        r15.<init>();	 Catch:{ Exception -> 0x0468 }
//        r18 = "transfer sum:";
//        r0 = r18;
//        r15 = r15.append(r0);	 Catch:{ Exception -> 0x0468 }
//        r15 = r15.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r15 = r15.toString();	 Catch:{ Exception -> 0x0468 }
//        cn.com.smartdevices.bracelet.GuliLog.tracePrintInfo(r8, r15);	 Catch:{ Exception -> 0x0468 }
//        if (r22 == 0) goto L_0x046a;
//    L_0x02a2:
//        r0 = r22;
//        r0.report(r5);	 Catch:{ Exception -> 0x0468 }
//        r8 = r7;
//        r7 = r5;
//        r5 = r4;
//        r4 = r9;
//        goto L_0x0187;
//    L_0x02ad:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x0234;
//    L_0x02b7:
//        r4 = "WeightProfile";
//        r5 = "DFU transfer rate: %.1f KBps";
//        r6 = 1;
//        r6 = new java.lang.Object[r6];	 Catch:{ Exception -> 0x0468 }
//        r7 = 0;
//        r8 = (float) r14;	 Catch:{ Exception -> 0x0468 }
//        r14 = java.lang.System.currentTimeMillis();	 Catch:{ Exception -> 0x0468 }
//        r14 = r14 - r16;
//        r9 = (float) r14;	 Catch:{ Exception -> 0x0468 }
//        r8 = r8 / r9;
//        r8 = java.lang.Float.valueOf(r8);	 Catch:{ Exception -> 0x0468 }
//        r6[r7] = r8;	 Catch:{ Exception -> 0x0468 }
//        r5 = java.lang.String.format(r5, r6);	 Catch:{ Exception -> 0x0468 }
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r4, r5);	 Catch:{ Exception -> 0x0468 }
//        r4 = 3;
//        r4 = new byte[r4];	 Catch:{ Exception -> 0x0468 }
//        r5 = 0;
//        r6 = 4;
//        r4[r5] = r6;	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        r6 = 65535; // 0xffff float:9.1834E-41 double:3.23786E-319;
//        r6 = r6 & r10;
//        r6 = (short) r6;	 Catch:{ Exception -> 0x0468 }
//        com.goodving.hm.health.bt.p094c.GattUtils.m25329a(r4, r5, r6);	 Catch:{ Exception -> 0x0468 }
//        r5 = 0;
//        r0 = r20;
//        r0.f19789G = r5;	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r0.write(r12, r4);	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        if (r4 != 0) goto L_0x02fa;
//    L_0x02f5:
//        r0 = r20;
//        r0.m25521a(r12, r11);	 Catch:{ Exception -> 0x0468 }
//    L_0x02fa:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        if (r4 == 0) goto L_0x0327;
//    L_0x0300:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.length;	 Catch:{ Exception -> 0x0468 }
//        r5 = 3;
//        if (r4 < r5) goto L_0x0327;
//    L_0x0308:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 0;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 16;
//        if (r4 != r5) goto L_0x0327;
//    L_0x0313:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 4;
//        if (r4 != r5) goto L_0x0327;
//    L_0x031d:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 2;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        if (r4 == r5) goto L_0x0387;
//    L_0x0327:
//        r2 = "WeightProfile";
//        r4 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x0468 }
//        r4.<init>();	 Catch:{ Exception -> 0x0468 }
//        r5 = "Invalid response: ";
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r5 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = com.goodving.hm.health.bt.p094c.GattUtils.m25335b(r5);	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.toString();	 Catch:{ Exception -> 0x0468 }
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r2, r4);	 Catch:{ Exception -> 0x0468 }
//        r2 = "WeightProfile";
//        r4 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x0468 }
//        r4.<init>();	 Catch:{ Exception -> 0x0468 }
//        r5 = "Firmware CRC: ";
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r5 = "%04X";
//        r6 = 1;
//        r6 = new java.lang.Object[r6];	 Catch:{ Exception -> 0x0468 }
//        r7 = 0;
//        r8 = java.lang.Integer.valueOf(r10);	 Catch:{ Exception -> 0x0468 }
//        r6[r7] = r8;	 Catch:{ Exception -> 0x0468 }
//        r5 = java.lang.String.format(r5, r6);	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.append(r5);	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.toString();	 Catch:{ Exception -> 0x0468 }
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r2, r4);	 Catch:{ Exception -> 0x0468 }
//        r2 = 1;
//        if (r3 == 0) goto L_0x0375;
//    L_0x0372:
//        r3.close();	 Catch:{ IOException -> 0x037e }
//    L_0x0375:
//        if (r12 == 0) goto L_0x0026;
//    L_0x0377:
//        r0 = r20;
//        r0.unregisterNotification(r12);
//        goto L_0x0026;
//    L_0x037e:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x0375;
//    L_0x0387:
//        r4 = "WeightProfile";
//        r5 = "reboot..................";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r4, r5);	 Catch:{ Exception -> 0x0468 }
//        r4 = 0;
//        r0 = r20;
//        r0.f19789G = r4;	 Catch:{ Exception -> 0x0468 }
//        r4 = 1;
//        r4 = new byte[r4];	 Catch:{ Exception -> 0x0468 }
//        r5 = 0;
//        r6 = 5;
//        r4[r5] = r6;	 Catch:{ Exception -> 0x0468 }
//        r0 = r20;
//        r4 = r0.write(r12, r4);	 Catch:{ Exception -> 0x0468 }
//        if (r4 != 0) goto L_0x03c1;
//    L_0x03a2:
//        r2 = "WeightProfile";
//        r4 = "Fail to issue restart command!";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r2, r4);	 Catch:{ Exception -> 0x0468 }
//        r2 = 1;
//        if (r3 == 0) goto L_0x03af;
//    L_0x03ac:
//        r3.close();	 Catch:{ IOException -> 0x03b8 }
//    L_0x03af:
//        if (r12 == 0) goto L_0x0026;
//    L_0x03b1:
//        r0 = r20;
//        r0.unregisterNotification(r12);
//        goto L_0x0026;
//    L_0x03b8:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x03af;
//    L_0x03c1:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        if (r4 != 0) goto L_0x03cc;
//    L_0x03c7:
//        r0 = r20;
//        r0.m25521a(r12, r11);	 Catch:{ Exception -> 0x0468 }
//    L_0x03cc:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        if (r4 == 0) goto L_0x03f9;
//    L_0x03d2:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r4 = r4.length;	 Catch:{ Exception -> 0x0468 }
//        r5 = 3;
//        if (r4 < r5) goto L_0x03f9;
//    L_0x03da:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 0;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 16;
//        if (r4 != r5) goto L_0x03f9;
//    L_0x03e5:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 5;
//        if (r4 != r5) goto L_0x03f9;
//    L_0x03ef:
//        r0 = r20;
//        r4 = r0.f19789G;	 Catch:{ Exception -> 0x0468 }
//        r5 = 2;
//        r4 = r4[r5];	 Catch:{ Exception -> 0x0468 }
//        r5 = 1;
//        if (r4 == r5) goto L_0x0418;
//    L_0x03f9:
//        r2 = "WeightProfile";
//        r4 = "Fail to wait restart command response!";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r2, r4);	 Catch:{ Exception -> 0x0468 }
//        r2 = 1;
//        if (r3 == 0) goto L_0x0406;
//    L_0x0403:
//        r3.close();	 Catch:{ IOException -> 0x040f }
//    L_0x0406:
//        if (r12 == 0) goto L_0x0026;
//    L_0x0408:
//        r0 = r20;
//        r0.unregisterNotification(r12);
//        goto L_0x0026;
//    L_0x040f:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x0406;
//    L_0x0418:
//        r4 = 0;
//        r0 = r20;
//        r0.f19788F = r4;	 Catch:{ Exception -> 0x0468 }
//        r20.m25298c();	 Catch:{ Exception -> 0x0468 }
//        if (r3 == 0) goto L_0x0425;
//    L_0x0422:
//        r3.close();	 Catch:{ IOException -> 0x0429 }
//    L_0x0425:
//        if (r12 == 0) goto L_0x0026;
//    L_0x0427:
//        goto L_0x0026;
//    L_0x0429:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x0425;
//    L_0x0432:
//        r2 = move-exception;
//        r3 = r4;
//    L_0x0434:
//        r2 = "WeightProfile";
//        r4 = "exception happend!!";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r2, r4);	 Catch:{ all -> 0x0466 }
//        r2 = 1;
//        if (r3 == 0) goto L_0x0441;
//    L_0x043e:
//        r3.close();	 Catch:{ IOException -> 0x044a }
//    L_0x0441:
//        if (r12 == 0) goto L_0x0026;
//    L_0x0443:
//        r0 = r20;
//        r0.unregisterNotification(r12);
//        goto L_0x0026;
//    L_0x044a:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x0441;
//    L_0x0453:
//        r2 = move-exception;
//        r3 = r4;
//    L_0x0455:
//        if (r3 == 0) goto L_0x045a;
//    L_0x0457:
//        r3.close();	 Catch:{ IOException -> 0x045d }
//    L_0x045a:
//        if (r12 == 0) goto L_0x045c;
//    L_0x045c:
//        throw r2;
//    L_0x045d:
//        r3 = move-exception;
//        r3 = "WeightProfile";
//        r4 = "Fail to operate on the firmware file";
//        cn.com.smartdevices.bracelet.GuliLog.m12370d(r3, r4);
//        goto L_0x045a;
//    L_0x0466:
//        r2 = move-exception;
//        goto L_0x0455;
//    L_0x0468:
//        r2 = move-exception;
//        goto L_0x0434;
//    L_0x046a:
//        r8 = r7;
//        r7 = r5;
//        r5 = r4;
//        r4 = r9;
//        goto L_0x0187;
//    L_0x0470:
//        r7 = r5;
//        r5 = r4;
//        r4 = r9;
//        goto L_0x0187;
//    L_0x0475:
//        r4 = r5;
//        goto L_0x024f;
//        */
//        throw new UnsupportedOperationException("Method not decompiled: com.goodving.hm.health.bt.profile.Weight.f.b(java.lang.String, com.goodving.hm.health.bt.d.b):int");
//    }

    private void m25514b(BluetoothGattCharacteristic bluetoothGattCharacteristic, int i) {
        byte[] bArr = new byte[f19781r];
        bArr[f19778o] = (byte) 4;
        GattUtils.m25329a(bArr, (int) f19779p, (short) (65535 & i));
        write(bluetoothGattCharacteristic, bArr);
    }

    public void m25521a(BluetoothGattCharacteristic bluetoothGattCharacteristic, int i) {
        synchronized (bluetoothGattCharacteristic) {
            try {
                bluetoothGattCharacteristic.wait((long) i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    class C3931k implements Runnable {
        final /* synthetic */ C0638c f19807a;
        final /* synthetic */ long f19808b;
        final /* synthetic */ WeightProfile f19809c;
        private byte f19810d;
        private byte f19811e;
        private byte f19812f;
        private byte f19813g;
        private byte f19814h;
        private boolean f19815i;
        private long f19816j;
        private long f19817k;
        private int f19818l;
        private int f19819m;
        private ArrayList<ScaleWeightInfo> f19820n;
        private int f19821o;

        C3931k(WeightProfile WeightProfile, C0638c c0638c, long j) {
            this.f19809c = WeightProfile;
            this.f19807a = c0638c;
            this.f19808b = j;
            this.f19810d = (byte) 0;
            this.f19811e = (byte) 1;
            this.f19812f = (byte) 2;
            this.f19813g = (byte) 3;
            this.f19814h = (byte) 4;
            this.f19815i = false;
            this.f19816j = -1;
            this.f19817k = -1;
            this.f19818l = -1;
            this.f19819m = 0;
            this.f19820n = new ArrayList();
            this.f19821o = 0;
        }

        private void m25537a(ArrayList<ScaleWeightInfo> arrayList) {
            C3933m c3933m = new C3933m();
            c3933m.f19826d = arrayList;
            c3933m.f19823a = this.f19816j;
            c3933m.f19824b = this.f19817k;
            c3933m.f19825c = this.f19821o;
            GuliLog.tracePrintInfo(WeightProfile.TAG, "Result:" + c3933m.toString());
            if (this.f19807a != null) {
                this.f19807a.m7912a(c3933m);
            }
        }

        private void frkHandleData(byte[] bArr) { // m25538a

            synchronized (this.f19809c.charc_write) {
                GuliLog.tracePrintInfo(WeightProfile.TAG, "in handleData:" + GattUtils.m25335b(bArr));
                if(bArr.length == 20) {
                    this.f19815i = false;
                    this.f19819m += 1;

                    long timestamp = byte2int(bArr, 0, 3);
                    Date date = new Date();
                    date.setTime(timestamp * 1000);
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(date);

                    byte[] fakeInfo = new byte[10];
                    // to build the fake timestamp.

                    int year = calendar.get(Calendar.YEAR);
                    fakeInfo[0] = 17;
                    fakeInfo[0] += (byte)ScaleWeightInfo.stable;
                    fakeInfo[0] += (byte)ScaleWeightInfo.finish;

                    int weightValue = ((0xff & bArr[5]) << 8 | (0xff &bArr[4]));
                    weightValue = weightValue * 10 ;
                    fakeInfo[1] = (byte)(weightValue & 0xff);
                    fakeInfo[2] = (byte)((weightValue >> 8)& 0xff);
                    fakeInfo[3] = (byte)(year & 0xff);
                    fakeInfo[4] = (byte)((year >> 8) & 0xff);
                    fakeInfo[5] = (byte)(calendar.get(Calendar.MONTH) + 1);
                    fakeInfo[6] = (byte)(calendar.get(Calendar.DATE));
                    fakeInfo[7] = (byte)(calendar.get(Calendar.HOUR_OF_DAY));
                    fakeInfo[8] = (byte)(calendar.get(Calendar.MINUTE));
                    fakeInfo[9] = (byte)(calendar.get(Calendar.SECOND));
                    //fakeInfo[9] = 0;

                    ScaleWeightInfo a = ProfileUtils.m25641a(fakeInfo, false, true);
                    if (this.f19809c.f19790H != null) {
                        a.m25485a(this.f19809c.f19790H.f19718a);
                    }
                    long e = a.m25494e();
                    if (a.m25499j() == 0.0f) {
                        this.f19821o++;
                        GuliLog.m12370d(WeightProfile.TAG, "wrong weight data value as reboot:" + a + "<DROP>!!!");
                    } else if (m25540a(e)) {
                        this.f19820n.add(a);
                        if (this.f19816j == -1) {
                            this.f19816j = e;
                        } else if (this.f19816j > e) {
                            this.f19816j = e;
                        }
                        if (this.f19817k == -1) {
                            this.f19817k = e;
                        } else if (this.f19817k < e) {
                            this.f19817k = e;
                        }
                        // TBD DEBUG
                        Log.e(TAG, "" + a.toString());
                    } else {
                        GuliLog.m12370d(WeightProfile.TAG, "wrong weight data timestamp:" + new Date(e).toString() + "<DROP>!!!");
                    }
                } else {
                    this.f19815i = true;
                }

                this.f19809c.charc_write.notify();
                GuliLog.tracePrintInfo(WeightProfile.TAG, "out handleData");
            }
        }

        private void handleData(byte[] bArr) { // m25538a
            int i = 0;
            int r3 = 0;
            synchronized (this.f19809c.f19783A) {
                GuliLog.tracePrintInfo(WeightProfile.TAG, "in handleData:" + GattUtils.m25335b(bArr));
                if (bArr.length == 1) {
                    this.f19815i = true;
                } else if (bArr.length == 3) {
                    if (bArr[0] != this.f19811e) {
                        this.f19815i = true;
                    } else {
                        this.f19815i = false;
                        this.f19818l = ((bArr[2] & HeartRateInfo.HR_EMPTY_VALUE) << 8) | (bArr[1] & HeartRateInfo.HR_EMPTY_VALUE);
                    }
                } else if (bArr.length == 7) {
                    if (bArr[0] != this.f19811e) {
                        this.f19815i = true;
                    } else {
                        boolean z = false;
                        this.f19818l = ((bArr[2] & HeartRateInfo.HR_EMPTY_VALUE) << 8) | (bArr[1] & HeartRateInfo.HR_EMPTY_VALUE);
                        r3 = ((((bArr[6] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | ((bArr[5] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((bArr[4] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | (bArr[3] & HeartRateInfo.HR_EMPTY_VALUE);
                        GuliLog.m12370d(WeightProfile.TAG, "data size:" + this.f19818l + ",weight uid:" + r3 + ",current uid:" + this.f19808b);
                        if (((long) r3) != this.f19808b) {
                            z = true;
                        }
                        this.f19815i = z;
                    }
                } else if (bArr.length == 10 || bArr.length == 20) {
                    this.f19815i = false;
                    byte[] obj = new byte[10];
                    r3 = bArr.length / 10;
                    this.f19819m += r3;
                    while (i < r3) {
                        System.arraycopy(bArr, i * 10, obj, 0, 10);
                        ScaleWeightInfo a = ProfileUtils.m25641a(obj, false, true);
                        if (this.f19809c.f19790H != null) {
                            a.m25485a(this.f19809c.f19790H.f19718a);
                        }
                        long e = a.m25494e();
                        if (a.m25499j() == 0.0f) {
                            this.f19821o++;
                            GuliLog.m12370d(WeightProfile.TAG, "wrong weight data value as reboot:" + a + "<DROP>!!!");
                        } else if (m25540a(e)) {
                            this.f19820n.add(a);
                            if (this.f19816j == -1) {
                                this.f19816j = e;
                            } else if (this.f19816j > e) {
                                this.f19816j = e;
                            }
                            if (this.f19817k == -1) {
                                this.f19817k = e;
                            } else if (this.f19817k < e) {
                                this.f19817k = e;
                            }
                        } else {
                            GuliLog.m12370d(WeightProfile.TAG, "wrong weight data timestamp:" + new Date(e).toString() + "<DROP>!!!");
                        }
                        i++;
                    }
                } else {
                    this.f19815i = true;
                }
                this.f19809c.f19783A.notify();
                GuliLog.tracePrintInfo(WeightProfile.TAG, "out handleData");
            }
        }

        private boolean doCommand(byte b, int i) { // m25539a
            GuliLog.tracePrintInfo(WeightProfile.TAG, "in doCommand:" + b);
            this.f19815i = true;
            if (b > 0) {
                if (b == this.f19811e || b == this.f19814h) {
                    this.f19809c.write(this.f19809c.f19783A, new byte[]{b, (byte) ((int) (this.f19808b & 255)), (byte) ((int) ((this.f19808b >> 8) & 255)), (byte) ((int) ((this.f19808b >> 16) & 255)), (byte) ((int) ((this.f19808b >> 24) & 255))});
                } else {
                    this.f19809c.write(this.f19809c.f19783A, new byte[]{b});
                }
            }
            if (!this.f19815i) {
                return true;
            }
            synchronized (this.f19809c.f19783A) {
                if (i > 0) {
                    try {
                        this.f19809c.f19783A.wait((long) i);
                    } catch (InterruptedException e) {
                        return false;
                    }
                }
            }
            GuliLog.tracePrintInfo(WeightProfile.TAG, "out doCommand:" + b);
            return !this.f19815i;
        }

        private boolean frkDoCommand(byte b, int i) { // m25539a
            GuliLog.tracePrintInfo(WeightProfile.TAG, "in frkDoCommand:" + b);
            this.f19815i = true;

            // here we need to get all record
            boolean result = write(this.f19809c.charc_write, new byte[]{b});

            if (!result) {
                GuliLog.tracePrintInfo(WeightProfile.TAG, "fail to get result");
                return true;
            }

            if (!this.f19815i) {
                return true;
            }
            synchronized (this.f19809c.charc_write) {
                if (i > 0) {
                    try {
                        this.f19809c.charc_write.wait((long) i);
                    } catch (InterruptedException e) {
                        return false;
                    }
                }
            }
            GuliLog.tracePrintInfo(WeightProfile.TAG, "out doCommand:" + b);
            return !this.f19815i;
        }

        private boolean m25540a(long j) {
            Calendar instance = Calendar.getInstance();
            instance.setTimeInMillis(j);
            if (instance.get(Calendar.YEAR) < 2014) {
                GuliLog.m12370d(WeightProfile.TAG, "year less than 2014!!!");
                return false;
            } else if (j <= Calendar.getInstance().getTimeInMillis() + 86400000) {
                return true;
            } else {
                GuliLog.m12370d(WeightProfile.TAG, "timestamp large than current!!!");
                return false;
            }
        }

        class C3932l implements INotifyCallback {
            final /* synthetic */ C3931k f19822a;

            C3932l(C3931k c3931k) {
                this.f19822a = c3931k;
            }

            public void notify(byte[] bArr) {
                if (devType == Constants.DEV_MI_SCALE) {
                    this.f19822a.handleData(bArr);
                } else if (devType == Constants.DEV_FRK_SCALE) {
                    this.f19822a.frkHandleData(bArr);
                }
            }
        }

        public void run() {
            if (devType == Constants.DEV_MI_SCALE) {
                if (this.f19807a != null) {
                    this.f19807a.m7910a();
                }
                if (this.f19809c.m25504A() == 3) {
                    GuliLog.m12370d(WeightProfile.TAG, "sand glass mode is test!!!");
                    this.f19809c.m25505B();
                }
                if (this.f19809c.f19783A == null) {
                    this.f19809c.f19783A = this.f19809c.f19793t.getCharacteristic(C3923a.B_);
                }
                if (this.f19809c.f19783A == null) {
                    GuliLog.m12370d(WeightProfile.TAG, "m_CharSyncControl is null!!!");
                    m25537a(null);
                    return;
                }
                this.f19809c.registerNotification(this.f19809c.f19783A, new C3932l(this));

                if (!doCommand(this.f19811e, 5000)) {
                    GuliLog.m12370d(WeightProfile.TAG, "CMD_GET_SIZE failed!!!");
                    doCommand(this.f19813g, 0);
                    m25537a(null);
                } else if (doCommand(this.f19812f, 5000)) {
                    do {
                    } while (doCommand(this.f19810d, 5000));
                    doCommand(this.f19813g, 0);
                    if (this.f19818l == this.f19819m) {
                        doCommand(this.f19814h, 0);
                    } else {
                        GuliLog.m12370d(WeightProfile.TAG, "received weight data size not match the head data size!!!");
                    }
                    this.f19809c.unregisterNotification(this.f19809c.f19783A);
                    if (this.f19818l != this.f19820n.size()) {
                        GuliLog.m12370d(WeightProfile.TAG, "valid weight data size not match the head data size!!!");
                        this.f19818l = this.f19820n.size();
                    }
                    m25537a(this.f19820n);
                } else {
                    GuliLog.m12370d(WeightProfile.TAG, "CMD_START_SYNC failed!!!");
                    doCommand(this.f19813g, 0);
                    m25537a(null);
                }
            } else if (devType == Constants.DEV_FRK_SCALE) {
                this.f19809c.registerNotification(this.f19809c.charc_record, new C3932l(this));

                boolean result = frkDoCommand((byte) 115, 5000);

                if(!result) {
                    GuliLog.m12370d(WeightProfile.TAG, "fail to get all record");
                }

                this.f19809c.unregisterNotification(this.f19809c.charc_record);
                if (this.f19818l != this.f19820n.size()) {
                    GuliLog.m12370d(WeightProfile.TAG, "valid weight data size not match the head data size!!!");
                    this.f19818l = this.f19820n.size();
                }
                m25537a(this.f19820n);
            } else {
                return;
            }

        }
    }

    public void runSyncDataTask(C0638c c0638c, long j) { // m25522a
        GuliLog.tracePrintInfo(TAG, "runSyncDataTask");
        if (j == -1) {
            GuliLog.m12370d(TAG, "invalid uid!!!");
        } else {
            this.f19787E.execute(new C3931k(this, c0638c, j));
        }
    }

    public void m25523a(C3849b c3849b) {
        this.f19786D = c3849b;
    }

    public void m25524a(C3847c c3847c) {
        this.f19785C = c3847c;
    }

    class C3930j implements Runnable {
        final /* synthetic */ C1725b f19804a;
        final /* synthetic */ String f19805b;
        final /* synthetic */ WeightProfile f19806c;

        C3930j(WeightProfile paraXMWeightBleGattCB, C1725b c1725b, String str) {
            this.f19806c = paraXMWeightBleGattCB;
            this.f19804a = c1725b;
            this.f19805b = str;
        }

        public void run() {
            if (this.f19804a != null) {
                this.f19804a.onStart(0);
            }
            this.f19806c.m25526b(false);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//            int a = this.f19806c.m25512b(this.f19805b, this.f19804a);
//            if (this.f19804a != null) {
//                this.f19804a.onStop(a);
//            }
        }
    }

    public void m25525a(String str, C1725b c1725b) {
        GuliLog.tracePrintInfo(TAG, "runFwUpgradeTask");
        this.f19787E.execute(new C3930j(this, c1725b, str));
    }

    public boolean m25526b(boolean z) {
        if (this.f19784B == null) {
            return false;
        }
        BluetoothGattCharacteristic bluetoothGattCharacteristic = this.f19784B;
        byte[] bArr = new byte[5];
        bArr[f19778o] = (byte) 2;
        bArr[f19779p] = (byte) (z ? f19779p : f19778o);
        bArr[f19780q] = (byte) 0;
        bArr[f19781r] = (byte) 0;
        bArr[f19782s] = (byte) 0;
        return write(bluetoothGattCharacteristic, bArr);
    }

    public void m25527r() {
        super.m25311r();
        this.f19785C = null;
    }

    class C3927g implements INotifyCallback {
        final /* synthetic */ WeightProfile f19800a;

        C3927g(WeightProfile c3926f) {
            this.f19800a = c3926f;
        }

        public void notify(byte[] bArr) {
            if (this.f19800a.f19786D != null && bArr != null && bArr.length == 1 && bArr[0] == 2) {
                this.f19800a.f19786D.m25173a();
            }
        }
    }

    class C3928h implements INotifyCallback {
        final /* synthetic */ WeightProfile f19801a;

        C3928h(WeightProfile c3926f) {
            this.f19801a = c3926f;
        }

        public void notify(byte[] bArr) {
            if (this.f19801a.f19785C != null) {
                ScaleWeightInfo a = ProfileUtils.m25641a(bArr, true, false);
                if (a != null) {
                    if (this.f19801a.f19790H != null) {
                        a.m25485a(this.f19801a.f19790H.f19718a);
                    }
                    this.f19801a.f19785C.m25171a(a);
                }
            }
        }
    }

    class FrkDataCallBack implements INotifyCallback {
        final /* synthetic */ WeightProfile profile;

        FrkDataCallBack(WeightProfile weightProfile) {
            this.profile = weightProfile;
        }

        public void notify(byte[] bArr) { // m25077a
            if (this.profile.f19785C != null) {
                // make a fake record with the timestamp

                byte[] fakeInfo = new byte[10];
                // to build the fake timestamp.
                Calendar gregorianCalendar = new GregorianCalendar();
                int year = gregorianCalendar.get(Calendar.YEAR);
                fakeInfo[0] = 17;
                if ((bArr[0] == 2)) {
                    fakeInfo[0] += (byte)ScaleWeightInfo.stable;
                } else {
                    //fakeInfo[0] += (byte)ScaleWeightInfo.finish;
                }
                int weightValue = ((0xff & bArr[2]) << 8 | (0xff &bArr[1]));
                weightValue = weightValue * 10 ;
                fakeInfo[1] = (byte)(weightValue & 0xff);
                fakeInfo[2] = (byte)((weightValue >> 8)& 0xff);
                fakeInfo[3] = (byte)(year & 0xff);
                fakeInfo[4] = (byte)((year >> 8) & 0xff);
                fakeInfo[5] = (byte)(gregorianCalendar.get(Calendar.MONTH) + 1);
                fakeInfo[6] = (byte)(gregorianCalendar.get(Calendar.DATE));
                fakeInfo[7] = (byte)(gregorianCalendar.get(Calendar.HOUR_OF_DAY));
                fakeInfo[8] = (byte)(gregorianCalendar.get(Calendar.MINUTE));
                //fakeInfo[9] = (byte)(gregorianCalendar.get(Calendar.SECOND));
                fakeInfo[9] = 0;

                ScaleWeightInfo a = ProfileUtils.m25641a(fakeInfo, true, false);
                if (a != null) {
                    if (this.profile.f19790H != null) {
                        a.m25485a(this.profile.f19790H.f19718a);
                    }
                    GuliLog.m12370d(TAG, "scale  information" + a.toString());
                    this.profile.f19785C.m25171a(a);
                }
            }
        }
    }

    class FrkRecordCallBack implements INotifyCallback {
        final /* synthetic */ WeightProfile profile;

        FrkRecordCallBack(WeightProfile weightProfile) {
            this.profile = weightProfile;
        }

        public void notify(byte[] bArr) { // m25077a
            if (this.profile.f19785C != null) {
                ScaleWeightInfo a = ProfileUtils.m25641a(bArr, true, false);
                if (a != null) {
                    if (this.profile.f19790H != null) {
                        a.m25485a(this.profile.f19790H.f19718a);
                    }
                    this.profile.f19785C.m25171a(a);
                }
            }
        }
    }

    public static long byte2int(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
    {
        long l = 0L;
        if (paramInt1 > paramInt2)
            paramInt1 = paramInt2;
        if (paramInt2 >= paramArrayOfByte.length)
            paramInt2 = -1 + paramArrayOfByte.length;
        int i = 0;
        while (true)
        {
            if (paramInt1 > paramInt2)
                return l;
            l += ((0xFF & paramArrayOfByte[paramInt1]) << i * 8);
            i++;
            paramInt1++;
        }
    }

    class FrkCommandCallBack implements INotifyCallback {
        final /* synthetic */ WeightProfile profile;

        FrkCommandCallBack(WeightProfile weightProfile) {
            this.profile = weightProfile;
        }

        public void notify(byte[] bArr) { // m25077a
            // to deal with the command return;
            if (this.profile.f19785C != null) {
                GuliLog.m12370d(TAG, "return command:" + bArr[0]);
                switch (bArr[0]) {
                    case 0x71:
                    case 0x76:
                        long timestamp = byte2int(bArr, 1, 4);
                        Date date = new Date();
                        date.setTime(timestamp * 1000);
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(date);
                        // TBD DEBUG
                        Log.e(TAG, "return time:" + calendar.getTime().toString());
                        break;

                    default:
                        break;

                }
            }
        }
    }

    private boolean frkSyncTimeStamp(Calendar calendar) {

        Calendar.getInstance();
        long l = new Date().getTime()/1000;

        byte byte0 = 114;
        byte byte1 = (byte)(l & 0xff);
        byte byte2 = (byte)((l >> 8) & 0xff);
        byte byte3 = (byte)((l >> 16) & 0xff);
        byte byte4 = (byte)((l >> 24) & 0xff);

        // TBD DEBUG
        // first to force the set the current time
        Log.e(TAG, "set date:" + calendar.getTime().toString());
        //GuliLog.m12370d(TAG, "set date:" + calendar.getTime().toString());
        boolean b = write(this.charc_write, new byte[]{byte0, byte1, byte2, byte3, byte4});
        if(!b) {
            return false;
        }

        // second to get the scale current time
        byte0 = 0x76;
        return write(this.charc_write, new byte[]{byte0});

    }

    private boolean frkInitCharacteristics() {
        BluetoothGattService frkGattService = getService(GattUtils.m25322a("FFCC"));
        GuliLog.ASSERT_NOT_NULL(frkGattService);
        if (frkGattService != null) {
            this.charc_data = frkGattService.getCharacteristic(GattUtils.m25322a("FFC3"));
            GuliLog.ASSERT_NOT_NULL(this.charc_data);
            if (this.charc_data == null) {
                return false;
            }
        }

        boolean b = registerNotification(this.charc_data, new FrkDataCallBack(this));
        GuliLog.ASSERTION_TRUE(b);
        if (!b) {
            return false;
        }

        this.charc_record = frkGattService.getCharacteristic(GattUtils.m25322a("FFC2"));
        GuliLog.ASSERT_NOT_NULL(this.charc_record);
        if (this.charc_record == null) {
            return false;
        }

        b = registerNotification(this.charc_record, new FrkRecordCallBack(this));
        GuliLog.ASSERTION_TRUE(b);
        if (!b) {
            return false;
        }

        this.charc_write = frkGattService.getCharacteristic(GattUtils.m25322a("FFC1"));
        GuliLog.ASSERT_NOT_NULL(this.charc_write);
        if (this.charc_write == null) {
            return false;
        }

        b = registerNotification(this.charc_write, new FrkCommandCallBack(this));
        GuliLog.ASSERTION_TRUE(b);
        if (!b) {
            return false;
        }

        b = frkSyncTimeStamp(GregorianCalendar.getInstance());
        GuliLog.ASSERTION_TRUE(b);
        if (b) {
//            Calendar y = m25531y();
//            if (y != null) {
//                GuliLog.m12370d(TAG, "old ble rtc date:" + y.getTime().toString());
//            }
//            this.f19790H = m25506C();
//            if (this.f19790H == null || !this.f19790H.m25456a()) {
//                return false;
//            }
            this.f19788F = true;
            return true;
        }
        GuliLog.m12370d(TAG, "setDateTime failed!!!");
        return false;
//        return true;

//        boolean b = registerNotification(this.f19794u, new C3928h(this));
//        GuliLog.ASSERTION_TRUE(b);
//        if (!b) {
//            return false;
//        }
        // set the timestamp
//        boolean b = m25510a(GregorianCalendar.getInstance());
//        GuliLog.ASSERTION_TRUE(b);
//        if (b) {
//            Calendar y = m25531y();
//            if (y != null) {
//                GuliLog.m12370d(TAG, "old ble rtc date:" + y.getTime().toString());
//            }
//            this.f19790H = m25506C();
//            if (this.f19790H == null || !this.f19790H.m25456a()) {
//                return false;
//            }
//            this.f19788F = true;
//            return true;
//        }
//        GuliLog.m12370d(TAG, "setDateTime failed!!!");
//        return false;
//        return true;

    }

    private boolean miInitCharacteristics() {
        // the first one is for low battery
        BluetoothGattService a = getService(C3923a.w_);
        GuliLog.ASSERT_NOT_NULL(a);
        if (a != null) {
            this.f19784B = a.getCharacteristic(C3923a.x_);
            if (this.f19784B != null) {
                registerNotification(this.f19784B, new C3927g(this));
            }
        }

        // the second is the scale service
        this.f19793t = getService(C3923a.y_);
        GuliLog.ASSERT_NOT_NULL(this.f19793t);
        if (this.f19793t == null) {
            return false;
        }


        this.f19794u = this.f19793t.getCharacteristic(C3923a.z_);
        GuliLog.ASSERT_NOT_NULL(this.f19794u);
        if (this.f19794u == null) {
            return false;
        }
        this.f19799z = this.f19793t.getCharacteristic(C3923a.f19746f);
        GuliLog.ASSERT_NOT_NULL(this.f19799z);
        if (this.f19799z == null) {
            return false;
        }
        GuliLog.ASSERTION_TRUE((this.f19799z.getProperties() & f19780q) > 0);
        GuliLog.ASSERTION_TRUE((this.f19799z.getProperties() & 8) > 0);
        a = getService(C3923a.C_);
        GuliLog.ASSERT_NOT_NULL(a);
        if (a == null) {
            return false;
        }
        this.f19795v = a.getCharacteristic(C3923a.E_);
        GuliLog.ASSERT_NOT_NULL(this.f19795v);
        if (this.f19795v == null) {
            return false;
        }
        this.f19797x = a.getCharacteristic(C3923a.f19747k);
        GuliLog.ASSERT_NOT_NULL(this.f19797x);
        if (this.f19797x == null) {
            return false;
        }
        this.f19796w = a.getCharacteristic(C3923a.D_);
        GuliLog.ASSERT_NOT_NULL(this.f19796w);
        this.f19798y = a.getCharacteristic(C3923a.f19748l);
        GuliLog.ASSERT_NOT_NULL(this.f19798y);
        boolean b = registerNotification(this.f19794u, new C3928h(this));
        GuliLog.ASSERTION_TRUE(b);
        if (!b) {
            return false;
        }
        b = m25510a(GregorianCalendar.getInstance());
        GuliLog.ASSERTION_TRUE(b);
        if (b) {
            Calendar y = m25531y();
            if (y != null) {
                GuliLog.m12370d(TAG, "old ble rtc date:" + y.getTime().toString());
            }
            this.f19790H = m25506C();
            if (this.f19790H == null || !this.f19790H.m25456a()) {
                return false;
            }
            this.f19788F = true;
            return true;
        }
        GuliLog.m12370d(TAG, "setDateTime failed!!!");
        return false;
    }

    protected boolean initCharacteristics() {
        GuliLog.m12371e();
        this.f19788F = false;
        GuliLog.ERROR("BT DEV INIT========== DEV TYPE:" + devType);
        switch (devType) {
            case Constants.DEV_FRK_SCALE:
                return frkInitCharacteristics();

            case Constants.DEV_MI_SCALE:
                return frkInitCharacteristics();
            default:
                return false;
        }

    }

    public boolean m25529u() {
        GuliLog.tracePrintInfo(TAG, "state:" + m25279g() + ",connect:" + this.f19788F);
        return m25279g() == XMBLEMSTATUS.CONNECTED && this.f19788F;
    }

    public final void m25530w() {
        GuliLog.m12371e();
        super.m25316w();
    }

    public Calendar m25531y() {
        GuliLog.m12371e();
        byte[] g = read(this.f19799z);
        if (g == null || g.length != 10) {
            return null;
        }
        GuliLog.ASSERTION_TRUE(g.length == 10);
        Calendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.set(Calendar.YEAR, (g[f19778o] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[f19779p] & HeartRateInfo.HR_EMPTY_VALUE) << 8));
        gregorianCalendar.set(Calendar.MONTH, g[f19780q] - 1);
        gregorianCalendar.set(Calendar.DATE, g[f19781r]);
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, g[f19782s]);
        gregorianCalendar.set(Calendar.MINUTE, g[5]);
        gregorianCalendar.set(Calendar.SECOND, g[6]);
        gregorianCalendar.set(Calendar.DAY_OF_WEEK, g[7]);
        return gregorianCalendar;
    }


    public int getDevType() {

        return this.devType;
    }

    public void setDevType(int devType) {
        this.devType = devType;
    }

    public C3911i m25532z() {
        return this.f19790H;
    }
}

